{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "416a3ef7",
   "metadata": {},
   "outputs": [],
   "source": [
    "xudan_token=\"24.f060e3b8a3ede1f1f3ecd4607a757474.2592000.1680924336.282335-31101345\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "34f6294e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result_num': 5, 'result': [{'keyword': '草原', 'score': 0.752331, 'root': '自然风景-草原', 'baike_info': {'baike_url': 'http://baike.baidu.com/item/%E8%8D%89%E5%8E%9F/225520', 'image_url': 'https://bkimg.cdn.bcebos.com/pic/d62a6059252dd42a2eb574e60f3b5bb5c9eab83a', 'description': '草原是地球生态系统的一种，分为热带草原、温带草原等多种类型，是地球上分布最广的植被类型。草原的形成原因是土壤层薄或降水量少时，草本植物受影响小，而木本植物无法广泛生长。中国是世界上草原资源最丰富的国家之一，草原总面积将近4亿公顷，占全国土地总面积的40%，为现有耕地面积的3倍。'}}, {'keyword': '花海', 'score': 0.591234, 'root': '植物-其它'}, {'keyword': '油菜花', 'score': 0.43299, 'root': '植物-其它'}, {'keyword': '自然公园', 'score': 0.273884, 'root': '自然风景-自然公园'}, {'keyword': '江岭', 'score': 0.093905, 'root': '植物-成片种植'}], 'log_id': 1636183085319969085}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "通用物体和场景识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('C:/Users/86181/电脑/Desktop/图图1.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img,'baike_num':1}\n",
    "access_token = xudan_token\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "90eeef68",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result_num': 5, 'result': [{'keyword': '美女', 'score': 0.737565, 'root': '人物-人物特写', 'baike_info': {'baike_url': 'http://baike.baidu.com/item/%E7%BE%8E%E5%A5%B3/109596', 'image_url': 'https://bkimg.cdn.bcebos.com/pic/91529822720e0cf3acdfc0280046f21fbe09aa3d', 'description': '美女，汉语词语，拼音是měi nǚ，意思是容貌姣好、仪态优雅的女子。'}}, {'keyword': '上衣', 'score': 0.581208, 'root': '商品-穿戴'}, {'keyword': '女人', 'score': 0.424542, 'root': '人物-人物特写'}, {'keyword': '头发', 'score': 0.269866, 'root': '人物-人物特写'}, {'keyword': '人物特写', 'score': 0.114091, 'root': '人物-人物特写'}], 'log_id': 1636183736466123096}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "通用物体和场景识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('C:/Users/86181/电脑/Desktop/图图2.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img,'baike_num':1}\n",
    "access_token = xudan_token\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b9a7eff6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
